package com.kim.smartring.service;

import com.kim.smartring.location.LocationUtils;
import com.kim.smartring.location.LocationUtils.OnLocationReceiver;
import com.kim.smartring.utils.ConfigUtils;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class LocationService extends Service {

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {

		if (!ConfigUtils.isUserAddressInfoAvailable()) { // 未拿到用户位置信息
			final LocationUtils locationUtils = LocationUtils.getInstance();
			locationUtils.doLocation(this, new OnLocationReceiver() {

				@Override
				public void onReceiver(boolean result) {
					if (!result) {
						locationUtils.startLocation();
					} else {
						stopSelf();
					}
				}
			});
		}
		stopSelf();
		return super.onStartCommand(intent, flags, startId);
	}

}
